package com.daocao.ds.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.daocao.ds.R;
import com.daocao.ds.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class SelectMenuTipsDilaog extends Dialog {


    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    @BindView(R.id.txt_tips)
    TextView txtTips;
    @BindView(R.id.btn_left)
    SuperButton btnLeft;
    @BindView(R.id.btn_right)
    SuperButton btnRight;
    @BindView(R.id.btn_center)
    SuperButton btnCenter;
    private Context context;


    public SelectMenuTipsDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public SelectMenuTipsDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_tips_select);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.CENTER;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = (int) (Util.getDisplayMetrics(context).heightPixels * 0.8);
        } else {
            lp.width = (int) (Util.getDisplayMetrics(context).widthPixels * 0.8);
        }
        mWindow.setAttributes(lp);
    }

    public SelectMenuTipsDilaog showTwoSelectData(String title, int imgRes, String tips, String left_text, String right_text) {
        txtTitle.setText(title);
        txtTips.setText(tips);
        if (imgRes != 0) {
            imgIcon.setImageResource(imgRes);
        }
        btnLeft.setText(left_text);
        btnRight.setText(right_text);

        btnLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onLeft();
                }
                dismiss();
            }
        });

        btnRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onRight();
                }
                dismiss();
            }
        });
        return this;
    }

    public SelectMenuTipsDilaog showOneSelectData(String title, int imgRes, String tips, String left_text) {
        txtTitle.setText(title);
        txtTips.setText(tips);
        if (imgRes != 0) {
            imgIcon.setImageResource(imgRes);
        }

        btnLeft.setVisibility(View.GONE);
        btnRight.setVisibility(View.GONE);
        btnCenter.setVisibility(View.VISIBLE);
        btnCenter.setText(left_text);
        btnCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onLeft();
                }
                dismiss();
            }
        });
        return this;
    }

    private OnChooseListener onChooseListener;

    public SelectMenuTipsDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }


    public interface OnChooseListener {
        void onLeft();

        void onRight();
    }
}
